﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace DSS_Simplex
{
    public partial class Sensitivity_Report : Form
    {
        public Sensitivity_Report()
        {
            
            InitializeComponent();
            string[] NonBasisVar = Mesin.ArrNonBasisVar;
            List<double[,]> list = Mesin.ListRepValue;
            int opt = list.Count();
            int index = list.ElementAt(0).GetLength(1); ;
            int jml_baris = list.ElementAt(0).GetLength(0) - 1;

            //DG variabel
            Mesin.Variable_Analysis();
            string[] Var_Analysis_Max = Mesin.Var_Analysis_Max;
            string[] Var_Analysis_Min = Mesin.Var_Analysis_Min;
            double[] Var_Dss_Value = Mesin.Var_Dss_Value;
            double[] ObjCoef = Mesin.CoefObj;
            //DG const
            Mesin.Constraint_Analysis();
            string[] Const_Analysis_Max = Mesin.Const_Analysis_Max;
            string[] Const_Analysis_Min = Mesin.Const_Analysis_Min;
            double[] Const_Dss_Value = Mesin.Const_Dss_Val;
            string[] NonBasis = Mesin.NonBasis;
            #region var

            DGVVAr.RowCount = ObjCoef.Count();
            DGVVAr.ColumnCount = 7;
            for (int i = 0; i < ObjCoef.Count(); i++)
            {
                DGVVAr.Rows[i].Cells[0].Value = NonBasisVar.ElementAt(i);
                DGVVAr.Rows[i].Cells[1].Value = Var_Dss_Value[i];
                DGVVAr.Rows[i].Cells[2].Value = -Math.Round(list.ElementAt(opt - 1)[0, i + 1], 3);

                if (Var_Analysis_Min[i] != "Infinity" && Var_Analysis_Max[i] != "Infinity")
                {
                    DGVVAr.Rows[i].Cells[3].Value = Math.Round(double.Parse(Var_Analysis_Min[i]), 3) + " <= D <= " + Math.Round(double.Parse(Var_Analysis_Max[i]), 3);
                }
                else if (Var_Analysis_Min[i] == "Infinity" && Var_Analysis_Max[i] != "Infinity") 
                {
                    DGVVAr.Rows[i].Cells[3].Value = Var_Analysis_Min[i] + " <= D <= " + Math.Round(double.Parse(Var_Analysis_Max[i]), 3);
                }
                else if (Var_Analysis_Min[i] != "Infinity" && Var_Analysis_Max[i] == "Infinity")
                {
                    DGVVAr.Rows[i].Cells[3].Value = Math.Round(double.Parse(Var_Analysis_Min[i]), 3) + " <= D <= " + Var_Analysis_Max[i];
                }
                else 
                {
                    DGVVAr.Rows[i].Cells[3].Value = Var_Analysis_Min[i] + " <= D <= " + Var_Analysis_Max[i];
                }
            }
            //jml sekarang
            for (int i = 0; i < ObjCoef.Count(); i++)
            {
                DGVVAr.Rows[i].Cells[5].Value = ObjCoef[i];
            }
            //jml minimal
            for (int i = 0; i < ObjCoef.Count(); i++)
            {
                if (Var_Analysis_Min[i] == "Infinity")
                {
                    DGVVAr.Rows[i].Cells[4].Value = "Infinity";
                }
                else
                {
                    DGVVAr.Rows[i].Cells[4].Value = Math.Round(ObjCoef[i] + double.Parse(Var_Analysis_Min[i]), 3);
                }
            }
            //jml maksimal
            for (int i = 0; i < ObjCoef.Count(); i++)
            {
                if (Var_Analysis_Max[i] == "Infinity")
                {
                    DGVVAr.Rows[i].Cells[6].Value = "Infinity";
                }
                else
                {
                    DGVVAr.Rows[i].Cells[6].Value = Math.Round(ObjCoef[i] + double.Parse(Var_Analysis_Max[i]), 3);
                }
            }

            #endregion

            #region const

            //DGConst
            DGVConst.RowCount = Const_Analysis_Max.Count();
            DGVConst.ColumnCount = 6;
            for (int i = 0; i < Const_Analysis_Max.Count(); i++)
            {
                DGVConst.Rows[i].Cells[0].Value = NonBasis[i];
                
                DGVConst.Rows[i].Cells[1].Value = Const_Dss_Value[i];
                if (Const_Analysis_Min[i] != "Infinity" && Const_Analysis_Max[i] != "Infinity")
                {
                    DGVConst.Rows[i].Cells[2].Value = Math.Round(double.Parse(Const_Analysis_Min[i]), 3) + " <= D <= " + Math.Round(double.Parse(Const_Analysis_Max[i]), 3);
                }
                else if (Const_Analysis_Min[i] != "Infinity" && Const_Analysis_Max[i] == "Infinity")
                {
                    DGVConst.Rows[i].Cells[2].Value = Math.Round(double.Parse(Const_Analysis_Min[i]), 3) + " <= D <= " + Const_Analysis_Max[i];
                }
                else if (Const_Analysis_Min[i] == "Infinity" && Const_Analysis_Max[i] != "Infinity")
                {
                    DGVConst.Rows[i].Cells[2].Value = Const_Analysis_Min[i] + " <= D <= " + Math.Round(double.Parse(Const_Analysis_Max[i]), 3);
                }
                else 
                {
                    DGVConst.Rows[i].Cells[2].Value = Const_Analysis_Min[i] + " <= D <= " + Const_Analysis_Max[i];
                }
            }
            //jml sekarang
            for (int i = 0; i < Const_Analysis_Max.Count(); i++)
            {
                DGVConst.Rows[i].Cells[4].Value = Math.Round(list.ElementAt(0)[i + 1, 0],3);
            }
            //jml minimal
            for (int i = 0; i < Const_Analysis_Min.Count(); i++)
            {
                DGVConst.Rows[i].Cells[3].Value = Math.Round(list.ElementAt(0)[i + 1, 0] + double.Parse(Const_Analysis_Min[i]), 3);
            }
            //jml maksimal
            for (int i = 0; i < Const_Analysis_Max.Count(); i++)
            {
                DGVConst.Rows[i].Cells[5].Value = Math.Round(list.ElementAt(0)[i + 1, 0] + double.Parse(Const_Analysis_Max[i]), 3);
            }

            #endregion
        }
        

        
        
    }
}
